package comun.casacentral.proxy.parceador;

import java.io.FileNotFoundException;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import comun.casacentral.log.CasaLogger;

public class UtilsXML {
	
		private XStream x;
		
		public UtilsXML(){
			CasaLogger.log("Utils constructor...");
			
			x = new XStream(new DomDriver());
		}

		public  String toXML (Object objeto,Class<?> clase){
			CasaLogger.log("Utils constructor...");
			x.processAnnotations(clase);
			String resultado = x.toXML(objeto);
			CasaLogger.log("xml : \n"+resultado);
			return resultado;
		}
		
		
		@SuppressWarnings("unchecked")
		public <T> T toClase (String xml, Class<T> clase) throws FileNotFoundException{
			CasaLogger.log("Utils constructor...");
			x.processAnnotations(clase);
			CasaLogger.log("xml : \n"+xml);
			T res = (T) x.fromXML(xml);
			return res;
			
		}

}
